package com.example.figurehecheng.controller.merchant;


import com.example.figurehecheng.common.context.BaseContext;
import com.example.figurehecheng.common.result.PageResult;
import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.OrderPageDTO;
import com.example.figurehecheng.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 宇科工作室
 * @since 2024-10-18
 */
@RestController("merchantOrderController")
@RequestMapping("/merchant/order")
@CrossOrigin
@RequiredArgsConstructor
@Api(tags = "订单管理")
@Slf4j
public class OrderController {

    private final IOrderService orderService;

    /**
     * 订单查询
     * @param orderPageDTO
     * @return
     */
    @GetMapping("/selectOrderPage")
    @ApiOperation("订单查询")
    public Result<PageResult> selectOrderPage(OrderPageDTO orderPageDTO){
        log.info("订单查询:{} {}",orderPageDTO, BaseContext.getCurrentId());
        PageResult pageResult = orderService.selectOrderPage(orderPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 完成订单
     * @param orderId
     * @return
     */
    @PutMapping("/complete/{orderId}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("orderId") Integer orderId){
        log.info("完成订单：{}", orderId);
        orderService.complete(orderId);
        return Result.success();
    }

}
